package com.xbongbong.pro.service.toolbox.statistic.help;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.constant.SizeConstant;
import com.xbongbong.paas.domain.entity.ext.OptionalRangeEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.OptionalRangeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.enums.TimeTypeEnum;
import com.xbongbong.pro.enums.errorcodes.StatisticsServicesErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.statistic.model.ChartModel;
import com.xbongbong.pro.statistic.pojo.FiscalYearTimePojo;
import com.xbongbong.pro.statistic.result.pojo.ChartResultBasePojo;
import com.xbongbong.pro.statistic.result.pojo.PkInfoPojo;
import com.xbongbong.pro.statistic.result.pojo.dto.ChartResultDTO;
import com.xbongbong.pro.statistic.through.pojo.dto.ResultThroughDTO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.enums.CompanyConfigEnum;
import com.xbongbong.sys.domain.entity.DepartmentEntity;
import com.xbongbong.sys.domain.entity.UserEntity;
import com.xbongbong.sys.enums.DataPermissionEnum;
import com.xbongbong.sys.model.CompanyConfigModel;
import com.xbongbong.sys.model.DepartmentModel;
import com.xbongbong.sys.model.UserModel;
import com.xbongbong.sys.util.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 处理pk榜范围设置的方法类
 * @author zcp
 * @version v1.0
 * @date 2019/4/4
 * @since v1.0
 */
@Component
public class ChartPkRuleHelp {

    private static final Logger LOG = LoggerFactory.getLogger(ChartPkRuleHelp.class);

    @Resource
    private ChartModel chartModel;
    @Resource
    private DepartmentModel departmentModel;
    @Resource
    private UserModel userModel;
    @Resource
    private CompanyConfigModel companyConfigModel;
    @Resource
    private ChartDtoHelp chartDtoHelp;


    /**
     * 公司pk榜默认配置初始化
     * @param pkChartList
     * @param corpid
     */
    public void initPkSetRule(List<ChartEntity> pkChartList, String corpid) throws XbbException {

        // 获取公司的所有部门
        List<DepartmentEntity> allDepList = departmentModel.findAllDepartment(corpid, false);
        List<OptionalRangeEntity> allDeps = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for (DepartmentEntity department : allDepList) {
            OptionalRangeEntity optionalRangeEntity = new OptionalRangeEntity();
            optionalRangeEntity.setId(String.valueOf(department.getId()));
            optionalRangeEntity.setName(department.getName());
            optionalRangeEntity.setProperty(BasicConstant.DEPT);
            allDeps.add(optionalRangeEntity);
        }
        JSONArray pkRuleArr = allDeps.isEmpty() ? null : JSONArray.parseArray(JSON.toJSONString(allDeps));

        boolean update = false;
        for(ChartEntity chartEntity : pkChartList){
            JSONArray joinRule = chartEntity.getJoinRule();
            JSONArray scopeRule = chartEntity.getScopeRule();
            Integer powerType = chartEntity.getPowerType();

            // 默认参与人为全公司（包含所有子部门）
            if(joinRule == null){
                update = true;
                chartEntity.setJoinRule(pkRuleArr);
            }
            // 默认可见权限为全公司（包含所有子部门）
            if(scopeRule == null){
                update = true;
                chartEntity.setScopeRule(pkRuleArr);
            }
            // 默认数据权限
            if(powerType == null) {
                update = true;
                chartEntity.setPowerType(BasicConstant.ZERO);
            }
        }

        if(update){
            chartModel.updateBatch(pkChartList, corpid);
        }
    }


    /**
     * 获取统计的共有筛选条件：只封装fiscalYearTimePojo、开始结束时间、dataPermission、userIdIn
     * 注：只处理基础字段，其他参数还需要在外部copy进入相应pojo
     * @param userEntity 登录员工
     * @param chartResultDTO 统计请求基础的参数（全参数在相应的实现chartResultBaseDTO的dto内，如chartResultDTO）
     * @param list 所有的pk榜
     * @param clazz 相应的统计pojo的class，如ChartResultPojo.class、ChartResultPkPojo.class
     * @return T 相应的统计pojo，如ChartResultPojo、ChartResultPkPojo
     * @throws XbbException
     * @author youli.chen
     * @date 2019/3/18 19:11
     * @since v1.0
     * @version v1.0
     */
    public <T> T getChartResultRulePojo(UserEntity userEntity, ChartResultDTO chartResultDTO, List<ChartEntity> list, Class<T> clazz) throws XbbException {
        ChartResultBasePojo chartResultBasePojo = new ChartResultBasePojo();
        /*--------处理时间FiscalYearTimePojo、财年、开始结束时间、开始结束时间list（分片）--------*/
        //设置FiscalYearTimePojo
        FiscalYearTimePojo fiscalYearTimePojo = chartResultDTO.getTimeFilter();
        if(fiscalYearTimePojo == null){
            fiscalYearTimePojo = new FiscalYearTimePojo();
        }
        //财年开始月份
        int startMonth = companyConfigModel.getFiscalStartMonth(userEntity.getCorpid());
        fiscalYearTimePojo.setStartMonth(startMonth);
        Integer timeType = fiscalYearTimePojo.getTimeType4DefaultMonth();
        TimeTypeEnum timeTypeEnum = TimeTypeEnum.getByCode(timeType);
        if (timeTypeEnum == null) {
            timeType = TimeTypeEnum.MONTH.getCode();
        }
        fiscalYearTimePojo.setTimeTypeEnum(timeTypeEnum);
        chartResultBasePojo.setFiscalYearTimePojo(fiscalYearTimePojo);
        Integer startTime = FiscalYearHelp.getStartTime(fiscalYearTimePojo, timeType, startMonth);
        Integer endTime = FiscalYearHelp.getEndTime(fiscalYearTimePojo, startTime, timeType, startMonth);
        //判断起始时间不能大于结束时间
        if (startTime > endTime || (Objects.equals(startTime, endTime) && !fiscalYearTimePojo.getStartTime().equals(fiscalYearTimePojo.getEndTime()))) {
            throw new XbbException(StatisticsServicesErrorCodeEnum.API_ERROR_224007, StatisticsServicesErrorCodeEnum.API_ERROR_224007.getMsg(),"，"+ I18nMessageUtil.getMessage(I18nStringConstant.END_TIME_REGULATIONS));
        }
        chartResultBasePojo.setStartTime(startTime);
        chartResultBasePojo.setEndTime(endTime);
        /*--------处理dataPermission--------*/
        //网关已经处理过dataPermission，无需再次计算
        int dataPermission = userModel.getDataPermission(userEntity, true);
        chartResultBasePojo.setDataPermission(dataPermission);
        /*--------处理userIdIn--------*/
        List<String> userIdIn = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        // 角色权限没图表查看权限，统计数据也放开
        if (!chartResultDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.CHART_VIEW.getAlias())) {
            userIdIn.add("-1");
        }
        // 统计参与人始终限定最终参与人
        Map<Long, List<String>> chartIdUserListMap = getRuleUserIdIn(userEntity, list, chartResultDTO, dataPermission);
        chartResultBasePojo.setUserIdIn(userIdIn);
        chartResultBasePojo.setChartIdUserListMap(chartIdUserListMap);
        /*--------把计算出的基础参数、和剩余其他参数都塞入clazz对应的实体内--------*/
        T resultPojo = BeanUtil.copyProperties(chartResultBasePojo, clazz, false);
        BeanUtil.copyProperties(chartResultDTO, resultPojo, false);
        return resultPojo;
    }
    /**
     * 获取userIdIn
     * @param userEntity     登录员工
     * @return java.util.List<java.lang.String> 最终参与人
     * @author youli.chen
     * @date 2019/2/14 9:18
     * @since v1.0
     * @version v1.0
     */
    public Map<Long, List<String>> getRuleUserIdIn(UserEntity userEntity, List<ChartEntity> list, ChartResultDTO chartResultDTO, Integer dataPermission) throws XbbException {
        //-------------------开始过滤pk榜对应的数据范围权限-------------------
        // 公司pk榜默认配置初始化
        initPkSetRule(list, userEntity.getCorpid());

        Map<Long, List<String>> chartIdUserListMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for(ChartEntity chartEntity : list){
            Long id = chartEntity.getId();
            // 该pk榜设置设置当前登陆人不可见，就直接过滤掉
            if(!getIsVisible(userEntity, chartEntity)){
                continue;
            }
            // 实际参与人
            List<String> inFactJoinUserList = inFactJoinUser(chartEntity, chartResultDTO, userEntity, dataPermission);
            // 保险起见，防止es报错，这里只截取前10000名员工参与统计
            if(inFactJoinUserList.size() > SizeConstant.PAGE_SIZE){
                inFactJoinUserList = inFactJoinUserList.subList(BasicConstant.ZERO, SizeConstant.PAGE_SIZE);
            }
            chartIdUserListMap.put(id, inFactJoinUserList);
        }
        return chartIdUserListMap;
    }


    /**
     * 获取用户在pk榜设置的可见范围内，是否可见
     *
     * @param user        用户实体
     * @param chartEntity 分组实体
     * @return
     * @throws
     * @author youli.chen
     * @date: 2020-09-10 09:16
     * @version v1.0
     * @since v1.0
     */
    private boolean getIsVisible(UserEntity user, ChartEntity chartEntity) {
        Integer scopeEnable = chartEntity.getEnable();
        if (scopeEnable == null || BasicConstant.NO_USE.equals(scopeEnable)) {
            return true;
        }

        JSONArray scopeRule = chartEntity.getScopeRule();
        List<OptionalRangeEntity> scopeRuleData;
        try {
            scopeRuleData = scopeRule.toJavaList(OptionalRangeEntity.class);
        } catch (JSONException e) {
            scopeRuleData = new ArrayList<>();
        }

        if (scopeRuleData.size() <= 0) {
            return true;
        }

        Set<Long> depIdArray = new HashSet<>();
        Set<Long> roleIdArray = new HashSet<>();
        Set<String> userIdArray = new HashSet<>();

        for (OptionalRangeEntity pojo : scopeRuleData) {
            String property = pojo.getProperty();
            String id = pojo.getId();

            // 部门或角色id
            Long longId;
            try {
                longId = Long.parseLong(id);
            } catch (NumberFormatException e) {
                longId = null;
            }

            if (OptionalRangeEnum.DEPT.getValue().equals(property)) {
                depIdArray.add(longId);
            } else if (OptionalRangeEnum.ROLE.getValue().equals(property)) {
                roleIdArray.add(longId);
            } else if (OptionalRangeEnum.USER.getValue().equals(property)) {
                userIdArray.add(id);
            }
        }

        if (depIdArray.isEmpty() || roleIdArray.isEmpty() || userIdArray.isEmpty()) {
            return true;
        }


        Map<String, Object> param = new HashMap<>(8);
        param.put("corpid", user.getCorpid());
        param.put("del", DelEnum.NORMAL.getDel());
        List<DepartmentEntity> allDepartmentList = departmentModel.findEntitys(param);

        boolean matchRole = false;
        boolean matchDep = false;
        boolean matchUser;

        // 角色匹配
        List<Integer> roleIds = user.roleIdsToList();
        for (long roleId : roleIds) {
            if (roleIdArray.contains(roleId)) {
                matchRole = true;
                break;
            }
        }

        // 如果部门规则包含全公司，则直接匹配
        if (depIdArray.contains(1L)) {
            matchDep = true;
        }

        // 获取有权限查看模板的部门以及子部门
        Set<Long> depIncludeSubSet = new LinkedHashSet<>();
        for (Long depId : depIdArray) {
            Set<Long> subDepIdList = UserUtil.getSubDepIdList(depId, allDepartmentList);
            depIncludeSubSet.addAll(subDepIdList);
        }
        List<Long> belongDepList = userModel.getUserBelongDeptIdList(user, false);
        belongDepList.retainAll(depIncludeSubSet);

        if (!belongDepList.isEmpty()) {
            matchDep = true;
        }

        // 自定义人员匹配
        matchUser = userIdArray.contains(user.getUserId());

        return matchRole || matchDep || matchUser;
    }

    /**
     * 获取部门id路由对应的部门
     * @param depId 部门id
     * @param departmentList 部门列表
     * @return
     */
    private Set<Long> getSubDepIdList(Long depId, List<DepartmentEntity> departmentList) {
        return UserUtil.getSubDepIdList(depId, departmentList);
    }

    /**
     * 获取用户在pk榜设置实际参与人
     *
     * @param chartEntity 分组实体
     * @return
     * @throws
     * @author youli.chen
     * @date: 2020-09-10 09:16
     * @version v1.0
     * @since v1.0
     */
    private List<String> inFactJoinUser(ChartEntity chartEntity, ChartResultDTO chartResultDTO, UserEntity userEntity, Integer dataPermission) throws XbbException{
        List<String> userIdIn = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        userIdIn.add("-1");
        String corpid = chartEntity.getCorpid();

        Integer scopeEnable = chartEntity.getEnable();
        if (scopeEnable == null || BasicConstant.NO_USE.equals(scopeEnable)) {
            return userIdIn;
        }

        JSONArray joinRule = chartEntity.getJoinRule();
        JSONArray removeRule = chartEntity.getRemoveRule();

        // 不设置参与人范围默认显示可见权限内的全部数据
        if (joinRule == null || joinRule.size() <= 0) {
            //是否开启“显示离职员工数据”
            boolean pkLeave = companyConfigModel.hasBeenEnable(corpid, CompanyConfigEnum.PK_LEAVE.getAlias(), "1");
            userIdIn = userModel.getPkUserIdIn(userEntity, pkLeave, dataPermission);
            return userIdIn;
        }

        // 获取参与人集合
        List<String> joins = calculationUserList(userIdIn, corpid, joinRule);

        // 获取不参与人集合
        List<String> removeUserIdIn = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<String> removes = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        if(removeRule != null){
            removes = calculationUserList(removeUserIdIn, corpid, removeRule);
        }
        joins.removeAll(removes);

        // 筛选范围
        /*--------处理userIdIn--------*/
        List<String> checkUserIdIn = chartDtoHelp.getRuleUserIdIn(chartResultDTO,chartEntity, userEntity, dataPermission, chartResultDTO.getCheckedDepId(), chartResultDTO.getCheckedUserId(),joins);
        joins.retainAll(checkUserIdIn);

        return joins;
    }

    /**
     * 计算pk榜范围设置参与规则参与人员
     * @param userIdIn
     * @param corpid
     * @param ruleArr
     * @return
     */
    public List<String> calculationUserList(List<String> userIdIn, String corpid, JSONArray ruleArr) throws XbbException{
        Set<Long> depIdArray = new HashSet<>();
        Set<Integer> roleIdArray = new HashSet<>();
        Set<String> userIdArray = new HashSet<>();

        List<OptionalRangeEntity> ruleData;
        try {
            ruleData = ruleArr.toJavaList(OptionalRangeEntity.class);
        } catch (JSONException | NullPointerException e) {
            ruleData = new ArrayList<>();
        }

        if (ruleData.size() <= 0) {
            return userIdIn;
        }

        for (OptionalRangeEntity pojo : ruleData) {
            String property = pojo.getProperty();
            String id = pojo.getId();

            if (OptionalRangeEnum.DEPT.getValue().equals(property)) {
                // 部门id
                Long longId;
                try {
                    longId = Long.parseLong(id);
                } catch (NumberFormatException e) {
                    longId = null;
                }
                depIdArray.add(longId);
            } else if (OptionalRangeEnum.ROLE.getValue().equals(property)) {
                // 角色id
                Integer integerId;
                try {
                    integerId = Integer.parseInt(id);
                } catch (NumberFormatException e) {
                    integerId = null;
                }
                roleIdArray.add(integerId);
            } else if (OptionalRangeEnum.USER.getValue().equals(property)) {
                userIdArray.add(id);
            }
        }

        if (depIdArray.isEmpty() && roleIdArray.isEmpty() && userIdArray.isEmpty()) {
            return userIdIn;
        }

        userIdIn.clear();

        // 如果部门规则包含全公司，则直接获取公司所有员工
        if(!depIdArray.isEmpty()){
            if (depIdArray.contains(1L)) {
                Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                map.put("corpid",corpid);
                map.put("columns","user_id,name");
                //是否开启“显示离职员工数据”
                boolean pkLeave = companyConfigModel.hasBeenEnable(corpid, CompanyConfigEnum.PK_LEAVE.getAlias(),"1");
                if(!pkLeave){
                    map.put("del", DelEnum.NORMAL.getDel());
                }
                List<UserEntity> userEntityList = userModel.findEntitys(map);
                userEntityList.forEach(userEntity -> userIdIn.add(userEntity.getUserId()));
                return userIdIn;
            } else {
                // 查询部门内的所有员工userId列表，1包含离职员工（不处理子部门，这里随用户选择）
                List<String> depUserList = userModel.getDepUserIdList(corpid, depIdArray, 1);
                depUserList.forEach(depUser -> userIdIn.add(depUser));
            }
        }

        if(!roleIdArray.isEmpty()){
            List<Integer> roleIdIn = new ArrayList<>(roleIdArray);
            List<String> roleUserList = userModel.getUserIdsByRoles(corpid, roleIdIn);
            roleUserList.forEach(roleId -> userIdIn.add(roleId));
        }

        if(!userIdArray.isEmpty()){
            List<String> joinIdIn = new ArrayList<>(userIdArray);
            userIdIn.addAll(joinIdIn);
        }

        return userIdIn;
    }

    /**
     * 获取pk榜穿透的userIdIn
     * 有利原有逻辑未处理非超管角色可见范围是全部数据的情况，因此做此处理
     *
     * @param chartEntity      图表实体
     * @param resultThroughDTO 穿透dto
     * @param userEntity       登录员工
     * @param dataPermission   数据权限
     * @param checkedDepId     选择的部门id
     * @param checkedUserId    选择的员工id
     * @return java.util.List<java.lang.String> 筛选的员工与下属取过交集后的userIds
     * @author zcp
     * @version v1.0
     * @since v1.0
     */
    public List<String> getUserIdIn4PkThrough(ChartEntity chartEntity, ResultThroughDTO resultThroughDTO, UserEntity userEntity, Integer dataPermission, Long checkedDepId, String checkedUserId) throws XbbException {
        ChartResultDTO chartResultDTO = new ChartResultDTO();
        BeanUtil.copyProperties(resultThroughDTO, chartResultDTO, true);
        // 实际参与人
        List<String> userIdIn = inFactJoinUser(chartEntity, chartResultDTO, userEntity, dataPermission);
        if (checkedDepId != null && checkedDepId != 1L) {
            List<Long> depIdIn = new ArrayList<>();
            depIdIn.add(checkedDepId);
            //1包含离职员工、包含隐藏部门
            List<String> checkUserIdIn = userModel.getUserIdsRecursionDep(depIdIn, userEntity.getCorpid(), 1, true);
            //取交集
            userIdIn.retainAll(checkUserIdIn);
        } else if (!StringUtil.isEmpty(checkedUserId)) {
            //看是否是自己下属
            if (userIdIn.contains(checkedUserId)) {
                userIdIn.clear();
                userIdIn.add(checkedUserId);
            } else {//不是下属，则置空
                userIdIn.clear();
            }
        }
        if (userIdIn.size() <= 0) {
            userIdIn.add("-1");
        }
        return userIdIn;
    }

    /**
     * 当pk可见数据范围是 `top3+数据权限` 时对pk结果集进行过滤
     *
     * @param chartResultDTO  入参实体
     * @param tempTop  首页 = 3 ，图表中心 = null
     * @param userEntity    当前用户实体
     * @param chartEntity   pk图表实体
     * @param pkData   pk结果集
     * @author zyy
     * @date 2022/5/25
     * @version v1.0
     */
    public List<PkInfoPojo> filterResults(ChartResultDTO chartResultDTO, Integer tempTop,UserEntity userEntity, ChartEntity chartEntity,List<PkInfoPojo> pkData) {
        Integer dataPermission = userEntity.getDataPermission();
        Integer top3Switch = chartResultDTO.getTop3Switch();
        //用户数据权限是否为全公司
        if(Objects.equals(DataPermissionEnum.ALL.getCode(),dataPermission)){
            return splitPkTop3(tempTop,pkData);
        }
        //获取当前用户数据权限可见的pk数据
        List<String> canSeeUserIdIn = chartDtoHelp.getUserIdIn(userEntity, dataPermission, chartResultDTO.getCheckedDepId(), chartResultDTO.getCheckedUserId(),chartResultDTO.getCheckedId(), chartResultDTO,1);
        List<PkInfoPojo> pkInfoPojoList = pkData.stream().filter(value -> canSeeUserIdIn.contains(value.getId())).collect(Collectors.toList());

        //非全公司数据权限，`展示公司top3` 未开启，按照数据权限展示
        if(!Objects.equals(BasicConstant.ZERO,top3Switch)){
            return splitPkTop3(tempTop,pkInfoPojoList);
        }

        List<PkInfoPojo> resultPkDataList;
        //`展示公司top3` 开关开启
        if(Objects.equals(BasicConstant.THREE,tempTop)){
            resultPkDataList = splitPkTop3(tempTop, pkData);
            //首页
            //数据权限为`仅自己`时才会在首页额外展示自己，否则为全公司top3
            if(Objects.equals(BasicConstant.ONE,dataPermission)){
                for (PkInfoPojo pkInfoPojo : pkInfoPojoList) {
                    if(pkInfoPojo.getId().equals(userEntity.getUserId())){
                        pkInfoPojo.setWhetherI(BasicConstant.ZERO);
                        resultPkDataList.add(pkInfoPojo);
                        break;
                    }
                }
            }
        } else {
            //图表中心： 全公司top3(所有排名前3的都要展示出来) + 数据权限可见
            //并集 & 去重，防止top3跟数据可见权限中存在相同的pk数据
            resultPkDataList = pkData.stream().filter(value -> value.getRank() <= 3).collect(Collectors.toList());
            pkInfoPojoList.removeAll(resultPkDataList);
            resultPkDataList.addAll(pkInfoPojoList);
        }
        //设置穿透
        handleThrough(resultPkDataList,pkInfoPojoList);
        return resultPkDataList;
    }

    /**
     * 设置穿透： 如果全公司前三的pk数据不在可见范围内，则穿透属性设置为null
     *
     * @param allTop3List
     * @param pkInfoPojoList
     * @author zyy
     * @date 2022/5/25
     * @version v1.0
     */
    private void handleThrough(List<PkInfoPojo> allTop3List, List<PkInfoPojo> pkInfoPojoList) {
        for (PkInfoPojo pkInfoPojo : allTop3List) {
            if(!pkInfoPojoList.contains(pkInfoPojo)){
                pkInfoPojo.setThrough(null);
            }
        }
    }

    /**
     * 根据请求来源获取pk数据
     *
     * @param tempTop 首页 = 3 ，图表中心 = null
     * @param pkData pk结果集
     * @return java.util.List<com.xbongbong.pro.statistic.result.pojo.PkInfoPojo>
     * @author zyy
     * @date 2022/5/25
     * @version v1.0
     */
    private List<PkInfoPojo> splitPkTop3(Integer tempTop,List<PkInfoPojo> pkData) {
        //首页只需要返回前3条数据
        if(Objects.equals(BasicConstant.THREE,tempTop)){
            return new ArrayList<>(pkData.subList(BasicConstant.ZERO,pkData.size() >= BasicConstant.THREE ? BasicConstant.THREE : pkData.size()));
        }
        return pkData;
    }
}
